//////////////////////////////////////////////////////page_home//////////////////////////////////
$(document).on("pageInit", "#page_home", function(e, pageId, $page) {
    my.givetitle('账户中心');
    setTimeout(function(){
    	  $.showPreloader()
    },1)

                  my.getlogintiaozhuan();
      	          key=my.get_key(my.getCookie('token'))
      	          var info={'u_userid':my.getCookie('id')}
    				  info=JSON.stringify(info)
                      info=my.cryptoASEencrypt(info,key)
      	              $.ajax({
      						type:"post",
      						url:api.useraccountinfo,
      						data:{
      							'api_value':info
      						},
      						async:true,
      						error:function(XMLHttpRequest){
      							$.hidePreloader();
      							$.alert("请求失败，请刷新重试");
      						},
      						success:function(data){
      							if(data.match("err_code")!=null){
      								$.hidePreloader();
      								switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);

      								}
      							}else{

      								    data=JSON.parse(data)
                                        data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
                                         console.log(data)
      								    $('.balance').text(config.danwei+data.balance)
      								    $('.total_revenue').text(config.danwei+data.total_revenue)
      								    if(data.withdrawal_state==0){
      								    	$('.withdrawal_state').attr('href','')
      								    }
      								    if(data.user_name==''){
      								         $('.user_name label').text('待认证用户')
      								    }else{
      								    	 $('.user_name label').text(data.user_name)
      								    }
      								    if(data.identity_state==1){
      								    	$('.identity_state img').attr('src','/h5car/img/icon/ok.png')
      								    	$('.identity_state a').attr('href',showOwnerUrl)
      								    	$('.identity_state span:first-child label').text(data.identity_statedoc)
      								    }else if(data.identity_state==0){//未认证
      								    	$('.identity_state a').attr('href',checkOwnerUrl)
      								    	$('.identity_state img').attr('src','/h5car/img/icon/no.png')
      								    	$('.identity_state span:first-child label').text(data.identity_statedoc)
      								    }else if(data.identity_state==2){//
      								    	$('.identity_state img').attr('src','/h5car/img/icon/no.png')
      								    	$('.identity_state span:first-child label').text(data.identity_statedoc)
      								    	$('.identity_state a').attr('href',showOwnerUrl)
      								    }else{
      								    	$('.identity_state a').attr('href',showOwnerUrl)
      								    	$('.identity_state img').attr('src','/h5car/img/icon/no.png')
      								    	$('.identity_state span:first-child label').text(data.identity_statedoc)
      								    }
      								    if(data.carmanage_state==1){
      								    	$('.carmanage_state img').attr('src','/h5car/img/icon/ok.png')
      								    	$('.carmanage_state span:first-child label').text(data.carmanage_doc.doc_one+" : "+data.carmanage_doc.count_one)
      								    	$('.carmanage_state span').eq(1).text(data.carmanage_doc.doc_two+" : "+data.carmanage_doc.count_two)
      								    	$('.carmanage_state span').eq(2).text(data.carmanage_doc.doc_thr+" : "+data.carmanage_doc.count_thr)
      								    }else{
      								    	$('.carmanage_state img').attr('src','/h5car/img/icon/no.png')
      								    	$('.carmanage_state span:first-child label').text(data.carmanage_doc)
      								    }
      								    if(data.credit_state==1){
      								    	$('.credit_state img').attr('src','/h5car/img/icon/ok.png')
      								    }
      								    $('.credit_state label').text('信用卡'+data.credit_doc)
      								    $('.cashcard_state label').text('提现卡'+data.cashcard_doc)
      								    if(data.setpassword_state==1){
      								    	$('.setpassword_state img').attr('src','/h5car/img/icon/ok.png')
      								    }else if(data.setpassword_state==0){
      								    	$('.setpassword_state img').attr('src','/h5car/img/icon/no.png')
      								    	$('.setpassword_state span:first-child label').text(data.setpassword_doc)
      								    }
      								    if(data.coupons_state==1){
      								    	$('.coupons_state span:first-child').text(data.coupons_doc)
      								    }
      								    $('.about_our span:first-child').text(data.about_our.telephone)
      							        $.hidePreloader();
      							    }
      							 }
      						  });
      			    //退出登录开始
      			    $('.tc').click(function(){
      			    	my.setCookie('token','',-1)
                        my.setCookie('id','',-1)
      			    	//$.router.loadPage("parkIndex.html");
                        $.router.load(loginoutParkUrl,true);
      			    })
      				$('.get-car-hold').click(function(){
      					$('.get-cash').hide();
      					$(this).hide()
      				})
      		        //下拉刷新start
      		        $(".pull-to-refresh-content-home").on('refresh',function() {
      		    	  var  key=my.get_key(my.getCookie('token'))
      		    	  var info={'u_userid':my.getCookie('id')}
    				  info=JSON.stringify(info)
                      info=my.cryptoASEencrypt(info,key).toString()
      	              $.ajax({
      						type:"post",
      						url:api.useraccountinfo,
      						data:{
      							'api_value':info
      						},
      						async:true,
      						error:function(){
      							$.pullToRefreshDone('.pull-to-refresh-content');
      							$.toast("请求失败，请刷新重试");
      						},
      						success:function(data){
      							if(data.match("err_code")!=null){
      								$.pullToRefreshDone('.pull-to-refresh-content');
      								switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);

      								}

      							}else{

      								    data=JSON.parse(data)
                                        data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    $('.balance').text(config.danwei+data.balance)
      								    $('.total_revenue').text(config.danwei+data.total_revenue)
      								    if(data.withdrawal_state==0){
      								    	$('.withdrawal_state').attr('href','')
      								    }
      								    if(data.user_name==''){
      								         $('.user_name label').text('待认证用户')
      								    }else{
      								    	 $('.user_name label').text(data.user_name)
      								    }
      								    if(data.identity_state==1){
      								    	$('.identity_state img').attr('src','/h5car/img/icon/ok.png')
      								    	$('.identity_state a').attr('href','showOwner.html')
      								    	$('.identity_state span:first-child label').text(data.identity_statedoc)
      								    }else if(data.identity_state==0){
      								    	$('.identity_state img').attr('src','/h5car/img/icon/no.png')
      								    	$('.identity_state span:first-child label').text(data.identity_statedoc)
      								    }else if(data.identity_state==2){
      								    	$('.identity_state img').attr('src','/h5car/img/icon/no.png')
      								    	$('.identity_state span:first-child label').text(data.identity_statedoc)
      								    	$('.identity_state a').attr('href','')
      								    }else if(data.identity_state==3){
      								    	$('.identity_state img').attr('src','/h5car/img/icon/no.png')
      								    	$('.identity_state span:first-child label').text(data.identity_statedoc)
      								    }
      								    if(data.carmanage_state==1){
      								    	$('.carmanage_state img').attr('src','/h5car/img/icon/ok.png')
      								    	$('.carmanage_state span:first-child label').text(data.carmanage_doc.doc_one+" : "+data.carmanage_doc.count_one)
      								    	$('.carmanage_state span').eq(1).text(data.carmanage_doc.doc_two+" : "+data.carmanage_doc.count_two)
      								    	$('.carmanage_state span').eq(2).text(data.carmanage_doc.doc_thr+" : "+data.carmanage_doc.count_thr)
      								    }else{
      								    	$('.carmanage_state img').attr('src','/h5car/img/icon/no.png')
      								    	$('.carmanage_state span:first-child label').text(data.carmanage_doc)
      								    }
      								    if(data.credit_state==1){
      								    	$('.credit_state img').attr('src','/h5car/img/icon/ok.png')
      								    }
      								    $('.credit_state label').text('信用卡'+data.credit_doc)
      								    $('.cashcard_state label').text('提现卡'+data.cashcard_doc)
      								    if(data.setpassword_state==1){
      								    	$('.setpassword_state img').attr('src','/h5car/img/icon/ok.png')
      								    }else if(data.setpassword_state==0){
      								    	$('.setpassword_state img').attr('src','/h5car/img/icon/no.png')
      								    	$('.setpassword_state span:first-child label').text(data.setpassword_doc)
      								    }
      								    if(data.coupons_state==1){
      								    	$('.coupons_state span:first-child').text(data.coupons_doc)
      								    }
      								    $('.about_our span:first-child').text(data.about_our.telephone)
      								    $.pullToRefreshDone('.pull-to-refresh-content');
      							   }
      							 }
      						  });
      		    })//下拉刷新end
});